
import java.awt.Component;
import java.awt.event.*;
import java.util.*;

import javax.swing.*;


@SuppressWarnings("serial")
public class PokerFileChooser extends JFrame implements ActionListener {
	private JFileChooser chooser;
	private JComboBox jbox;
	private String selected;
	private int returned=0;
	
	public PokerFileChooser(Set<String> rl) {
		JSplitPane jsp=new JSplitPane();
		chooser=new JFileChooser();
		jbox=new JComboBox();
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		jbox.addActionListener(this);
		chooser.addActionListener(this);
		jsp.setOrientation(JSplitPane.VERTICAL_SPLIT);
		jsp.add(jbox, JSplitPane.TOP);
		jsp.add(chooser, JSplitPane.BOTTOM);

		if(rl!=null)
		for(String s:rl)
			jbox.addItem(s);
		
		this.add(jsp);
		this.setSize(320,200);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)){
			selected=chooser.getSelectedFile().getAbsolutePath();
			returned=1;
		}
		else if(e.getActionCommand().equals(JFileChooser.CANCEL_SELECTION)){
			returned=-1;
			selected=null;
			jbox.setSelectedItem(null);
		}
	}
	
	public Map<String, String> getSelected()
	{
		Map<String, String> eredmeny=new HashMap<String,String>();
		eredmeny.put(jbox.getSelectedItem().toString(),selected);
		return eredmeny;
	}

	public void showOpenDialog(Component control) {
		this.setVisible(true);
	}
	
	public int getReturnValue(){
		return returned;
	}
	
}
